<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
    * {
        padding: 0;
        margin: 0;
    }

    #canvas {
        position: absolute;
        top: 0;
        bottom: 0;
        right: 0;
        left: 0;
        margin: auto;
    }
    </style>
</head>

<body>
    <canvas id="canvas" width="800" height="500" style="border: 1px solid red"></canvas>
    <script>
    window.onload = function() {
        var canvas = document.getElementById('canvas');
        var ctx = canvas.getContext('2d');
        var width = canvas.width;
        var height = canvas.height;

        canvas.onmousedown = function(e) {
            ctx.beginPath();
            ctx.moveTo(e.offsetx, e.offsetY);
            document.onmousemove = function(e) {
                ctx.lineTo(e.offsetX, e.offsetY);
                ctx.lineWidth = 10;
                ctx.stroke();
            }
            document.onmouseup = function (e){
            	document.onmousedown = null;
            	document.onmousemove = null;
            }
        }
    }
    </script>
</body>

</html>